/**
 * @author 
 * @createtime 
 * @class MeetingEvaluationForm
 * @extends Ext.Window
 * @description MeetingEvaluation表单
 */
MeetingEvaluationForm=Ext.extend(Ext.Window,{
	//内嵌FormPanel
	formPanel:null,
	mainPanel:null,
	//构造函数
	constructor:function(_cfg){
		Ext.applyIf(this,_cfg);
		//必须先初始化组件
		this.initUIComponents();
		MeetingEvaluationForm.superclass.constructor.call(this,{
			id:'MeetingEvaluationFormWin',
			layout:'border',
			items:[this.mainPanel,this.formPanel],
			modal:true,
			height:300,
			width:700,
			maximizable:true,
			title:'[会议评价]详细信息',
			buttonAlign : 'center',
			buttons:this.buttons
		});
	},//end of the constructor
	//初始化组件
	initUIComponents:function(){
		this.mainPanel = new Ext.FormPanel({
					layout : 'form',
					region : 'north',
					bodyStyle : 'padding:6px 10px 6px 10px',
					border : false,
					frame : true,
					height : 50,
					items : [
							{
								xytpe:'container',
								layout:'column',
								defaults : {
									border : false,
									anchor : '98%,98%',
									xtype:'label',
									style : 'margin-left:5px;margin-top:5px;'
								},
								items:[
									{
										text : '申请人:'
									}, {
										id:'applyUserLabel'
									}, {
										text : '会议标题:'
									}, {
										id:'meetingTitleLabel'
									}
								]
							}]
				});// end of the mainPanel
		this.formPanel=new Ext.FormPanel({
				layout : 'form',
				trackResetOnLoad:true,
				bodyStyle: 'padding:10px 10px 10px 10px',
				border:false,
				region : 'center',
				url : __ctxPath + '/statistics/saveMeetingEvaluation.do',
				id : 'MeetingEvaluationForm',
				defaults : {
					anchor : '98%,98%'
				},
				defaultType : 'textfield',
				items : [{
								name : 'meetingEvaluation.id',
								id : 'id',
								xtype : 'hidden',
								value : this.id == null ? '' : this.id
							},{
								name : 'meetingEvaluation.meetingApply.id',
								id : 'meetingEvaluation.meetingApply.id',
								xtype : 'hidden',
								value : this.meetingId == null ? '' : this.meetingId
							}, {
								fieldLabel : '会议评级',
								hiddenName : 'meetingEvaluation.level',
								id : 'level',
								xtype : 'combo',
								mode:'local',
								triggerAction : "all",
								store : ['1分','2分','3分','4分','5分']
							}, {
								fieldLabel : '会议成果说明',
								name : 'meetingEvaluation.achievement',
								id : 'achievement',
								xtype:'textarea'
							},{
							xtype : 'container',
							autoHeight : true,
							layout : 'column',
							autoWidth : true,
							defaultType : 'label',
							style : 'padding-left:0px;padding-bottom:5px;',
							items : [{
										text : '附件:',
										width:95,
										style : "margin-top:15px;"
									},{
										xtype : 'hidden',
										name : 'attachIds',
										id : 'meetingEvaluation.attachIds'
									},{
										xtype : 'hidden',
										name : 'attachFiles',
										id : 'meetingEvaluation.attachFiles'
									},{
										xtype : 'panel',
										id:'meetingEvaluation.displayAttach',
										columnWidth:.95,
										height: 65,
										frame:false,
										autoScroll:true,
										style : 'padding-left:10px;padding-top:0px;',
										html : ''
									},{
										xtype : 'button',
										iconCls : 'btn-upload',
										text : '上传',
										handler : function() {
											var dialog = App.createUploadDialog({
																	file_cat : 'flow/meetingEvaluation',
																	callback : function(data) {
																		Ext.getCmp('meetingEvaluation.displayAttach').body.update('');
																		Ext.getCmp("meetingEvaluation.attachFiles").setValue('');
																		Ext.getCmp('meetingEvaluation.attachIds').setValue('');
																		var attachFiles = Ext.getCmp("meetingEvaluation.attachFiles");
																		var fileIds = Ext.getCmp('meetingEvaluation.attachIds');
																		var display = Ext.getCmp('meetingEvaluation.displayAttach');
																		for (var i = 0; i < data.length; i++) {
																			if (fileIds.getValue() != '') {
																				fileIds.setValue(fileIds.getValue()+ ',');
																				attachFiles.setValue(attachFiles.getValue()+ ',');
																			}
																			attachFiles.setValue(attachFiles.getValue()+data[i].filepath+":"+data[i].filename.replace(/\s+/g,""));
																			fileIds.setValue(fileIds.getValue()+data[i].fileId);
																			Ext.DomHelper.append(display.body,'<span><a href="#" onclick="FileAttachDetail.show('+data[i].fileId+')">'+data[i].filename.replace(/\s+/g,"")+'</a>&nbsp;|&nbsp;</span>');
																		}
																	},
																	permitted_max_size :1024*1024*20
																});
												dialog.show(this);
										}
									}]
						}
					]
			});
		// 加载表单对应的数据
		this.initData();
		// 初始化功能按钮
		this.buttons=[{
				text : '保存',
				iconCls : 'btn-save',
				handler :this.save.createCallback(this.formPanel,this)
			}, {
				text : '重置',
				iconCls : 'btn-reset',
				handler :this.reset.createCallback(this.formPanel)
			},{
				text : '取消',
				iconCls : 'btn-cancel',
				handler : this.cancel.createCallback(this)
			}];
	},//end of the initcomponents
	/**
	 * 初始化数据
	 * @param {} formPanel
	 */
	initData:function(){
		if (this.meetingId != null && this.meetingId != 'undefined') {
			this.mainPanel.getForm().load({
				deferredRender : false,
				url : __ctxPath + '/statistics/getMeetingApply.do?id='+ this.meetingId,
				waitMsg : '正在载入数据...',
				success : function(form, action) {
						var jsonData = Ext.util.JSON.decode(action.response.responseText);
						var res = jsonData.data;
						Ext.getCmp("applyUserLabel").setText("<font color='green'>"+res.applyUser.fullname+"</font>",false);
						Ext.getCmp("meetingTitleLabel").setText("<font color='green'>"+res.meetingTitle+"</font>",false);
				},
				failure : function(form, action) {
				}
			});
		Ext.getCmp("meetingEvaluation.meetingApply.id").setValue(this.meetingId);
		Ext.getCmp("meetingEvaluation.meetingApply.id").originalValue=this.meetingId;
		//加载表单对应的数据	
			this.formPanel.getForm().load({
				deferredRender : false,
				url : __ctxPath + '/statistics/getMeetingEvaluation.do?id='+ this.meetingId,
				waitMsg : '正在载入数据...',
				success : function(form, action) {
						var jsonData = Ext.util.JSON.decode(action.response.responseText);
						var res = jsonData.data;
						//Ext.getCmp("").originalValue=
						var af = res.fileAttachs;
						var filePanel = Ext.getCmp('meetingEvaluation.displayAttach');
						var fileIds = Ext.getCmp("meetingEvaluation.attachIds");
						for (var i = 0; i < af.length; i++) {
							if (fileIds.getValue() != '') {
								fileIds.setValue(fileIds.getValue() + ',');
							}
							fileIds.setValue(fileIds.getValue() + af[i].fileId);
							Ext.DomHelper
									.append(
											filePanel.body,
											'<span><a href="#" onclick="FileAttachDetail.show('
													+ af[i].fileId
													+ ')">'
													+ af[i].fileName.replace(/\s+/g,"")+'</a>&nbsp;|&nbsp;</span>');
						}
						fileIds.originalValue = fileIds.getValue();
				},
				failure : function(form, action) {
				}
			});
		}
	},
	/**
	 * 重置
	 * @param {} formPanel
	 */
	reset:function(formPanel){
		formPanel.getForm().reset();
	},
	/**
	 * 取消
	 * @param {} window
	 */
	cancel:function(window){
		window.close();
	},
	/**
	 * 保存记录
	 */
	save:function(formPanel,window){
		if (formPanel.getForm().isValid()) {
			formPanel.getForm().submit({
				method : 'POST',
				waitMsg : '正在提交数据...',
				success : function(fp, action) {
					Ext.ux.Toast.msg('操作信息', '成功保存信息！');
					var gridPanel=Ext.getCmp('MeetingApplyGrid');
					if(gridPanel!=null){
						gridPanel.getStore().reload();
					}
					window.close();
				},
				failure : function(fp, action) {
					Ext.MessageBox.show({
								title : '操作信息',
								msg : '信息保存出错，请联系管理员！',
								buttons : Ext.MessageBox.OK,
								icon : Ext.MessageBox.ERROR
							});
					window.close();
				}
			});
		}
	}//end of save
	
});